package com.zhengtoudai.ui.activity;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;

import com.zhengtoudai.R;
import com.zhengtoudai.base.BaseActivity;
import com.zhengtoudai.http.HttpApi;
import com.zhengtoudai.view.ProgressWebView;

import butterknife.Bind;
import butterknife.ButterKnife;

public class WebViewActivity extends BaseActivity {
    @Bind(R.id.webView)
    ProgressWebView webView;
    @Bind(R.id.tv_html)
    TextView mTvHtml;
    private String title;
    private String mUrl;
    private String mHtml;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_webview);
        ButterKnife.bind(this);
        title = getIntent().getStringExtra("title");
        mUrl = getIntent().getStringExtra("url");
        mHtml = getIntent().getStringExtra("html");
        super.onCreate(savedInstanceState);
    }


    @Override
    protected void initTitle() {
        titleUtil.setTitle(title);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    protected void initView() {

        if (!TextUtils.isEmpty(mUrl)) {
            webView.loadUrl(mUrl, HttpApi.getHeader());
            Log.e("url", mUrl);
        } else if (!TextUtils.isEmpty(mHtml)) {
            webView.loadDataWithBaseURL(null, mHtml, "text/html", "utf-8", null);

            /*webView.setVisibility(View.GONE);
            mTvHtml.setText(Html.fromHtml(mHtml));*/
            Log.e("html", mHtml);
        }

    }

    @Override
    public void onBackPressed() {
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            super.onBackPressed();
        }
    }

}
